package com.north.light.androidutils.libpicsel;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.north.light.androidutils.R;
import com.north.light.libpicselect.PicActionListener;
import com.north.light.libpicselect.PicCallbackListener;
import com.north.light.libpicselect.PicSelMain;
import com.north.light.libpicselect.PicSelParamsBuilder;
import com.north.light.libpicselect.callback.LibPicSelMediaInfo;
import com.north.light.libpicselect.model.LibPicSelConfig;

import java.util.ArrayList;

public class LibPicSelActivity extends AppCompatActivity {

    private static final String TAG = LibPicSelActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lib_pic_sel);
        //初始化
        PicSelMain.getInstance().init(this.getApplicationContext(), new LibPicSelConfig.BindImageViewListener() {
            @Override
            public void BindImageView(String path, ImageView iv) {
                Glide.with(LibPicSelActivity.this.getApplicationContext()).load(path).into(iv);
            }

            @Override
            public void BindSmallImageView(String path, ImageView iv) {
                Glide.with(LibPicSelActivity.this.getApplicationContext()).load(path).into(iv);
            }

            @Override
            public void BindResume() {
                Glide.with(LibPicSelActivity.this.getApplicationContext()).resumeRequests();
            }

            @Override
            public void BindPause() {
                Glide.with(LibPicSelActivity.this.getApplicationContext()).pauseRequests();
            }
        });
        PicSelMain.getInstance().setActionListener(new PicActionListener() {
            @Override
            public void cusVideoPlay(Activity activity, String path) {
                Log.d(TAG, "cusVideoPlay: " + (new Gson().toJson(path)));
            }

            @Override
            public void cusCameraTake(Activity activity) {
                Log.d(TAG, "cusCameraTake: ");
            }
        });
        //拍摄回调
        PicSelMain.getInstance().setPicCallBackListener(new PicCallbackListener() {
            @Override
            public void cameraResult(LibPicSelMediaInfo path) {
                Log.d(TAG, "cameraResult: " + (new Gson().toJson(path)));
            }

            @Override
            public void selectResult(ArrayList<LibPicSelMediaInfo> result) {
                Log.d(TAG, "selectResult: " + (new Gson().toJson(result)));
            }

            @Override
            public void cropResult(LibPicSelMediaInfo path) {
                Log.d(TAG, "cropResult: " + (new Gson().toJson(path)));

            }

            @Override
            public void recordVideoPath(LibPicSelMediaInfo path) {
                Log.d(TAG, "recordVideoPath: " + (new Gson().toJson(path)));

            }

            @Override
            public void error(String message) {
                Log.d(TAG, "error: " + message);

            }
        });
        PicSelParamsBuilder builder = new PicSelParamsBuilder();
        builder.getSelPicList().add("/storage/emulated/0/Pictures/DefaultPath/1657706641760.jpg");
        builder.getSelPicList().add("/storage/emulated/0/DCIM/1656742072080.jpg");
        builder.getSelPicList().add("/storage/emulated/0/pictures/image/IMG_20220702_152520.jpg");

        PicSelMain.getInstance().getPic(this, true, 1,
                true, true, 1, 1, builder);


    }
}